package com.shunda.trade.service.impl;

import com.shunda.trade.entity.TradeWithdrawalsFlow;
import com.shunda.trade.mapper.TradeWithdrawalsFlowMapper;
import com.shunda.trade.service.TradeWithdrawalsFlowService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户信息表(TradeWithdrawalsFlow)表服务实现类
 *
 * @author makejava
 * @since 2025-03-13 21:36:54
 */
@Service("tradeWithdrawalsFlowService")
public class TradeWithdrawalsFlowServiceImpl implements TradeWithdrawalsFlowService {
    @Resource
    private TradeWithdrawalsFlowMapper tradeWithdrawalsFlowDao;

    /**
     * 通过ID查询单条数据
     *
     * @param flowId 主键
     * @return 实例对象
     */
    @Override
    public TradeWithdrawalsFlow queryById(Long flowId) {
        return this.tradeWithdrawalsFlowDao.queryById(flowId);
    }

    /**
     * 分页查询
     *
     * @param tradeWithdrawalsFlow 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TradeWithdrawalsFlow> queryByPage(TradeWithdrawalsFlow tradeWithdrawalsFlow, PageRequest pageRequest) {
        long total = this.tradeWithdrawalsFlowDao.count(tradeWithdrawalsFlow);
        return new PageImpl<>(this.tradeWithdrawalsFlowDao.queryAllByLimit(tradeWithdrawalsFlow, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tradeWithdrawalsFlow 实例对象
     * @return 实例对象
     */
    @Override
    public TradeWithdrawalsFlow insert(TradeWithdrawalsFlow tradeWithdrawalsFlow) {
        this.tradeWithdrawalsFlowDao.insert(tradeWithdrawalsFlow);
        return tradeWithdrawalsFlow;
    }

    /**
     * 修改数据
     *
     * @param tradeWithdrawalsFlow 实例对象
     * @return 实例对象
     */
    @Override
    public TradeWithdrawalsFlow update(TradeWithdrawalsFlow tradeWithdrawalsFlow) {
        this.tradeWithdrawalsFlowDao.update(tradeWithdrawalsFlow);
        return this.queryById(tradeWithdrawalsFlow.getFlowId());
    }

    /**
     * 通过主键删除数据
     *
     * @param flowId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long flowId) {
        return this.tradeWithdrawalsFlowDao.deleteById(flowId) > 0;
    }

    @Override
    public List<TradeWithdrawalsFlow> selectWithdrawFlowPage(TradeWithdrawalsFlow withdrawalsFlow) {
        return tradeWithdrawalsFlowDao.selectWithdrawFlowPage(withdrawalsFlow);
    }
}
